import java.util.Stack;

/*
 *@Student 张策
 */
public class a {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c1 = s.charAt(i);
            if (c1 == '(' || c1 == '[' || c1 == '{') {
                stack.push(c1);
            }else {
                if(stack.isEmpty()){
                    return false;
                }
                char c2= stack.peek();
                if(c1==')'&&c2=='('||c1=='}'&&c2=='{'||c1==']'&&c2=='['){
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if (!stack.isEmpty()){
            return false;
        }
        return true;
    }
}